package yifeng.net.socket;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {
	
	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		
		
		try {
			ServerSocket ss = new ServerSocket(10000);
//			System.out.println(ss);
//			System.out.println(ss.getInetAddress());
//			System.out.println(ss.getLocalSocketAddress());
			
			while(true){
				System.out.println("waiting for client:");
				Socket s = ss.accept();
				
				
				System.out.println(s.getLocalPort());
				System.out.println(s.getLocalSocketAddress());
				System.out.println(s.getPort());
				System.out.println(s.getRemoteSocketAddress());
				BufferedReader br = new BufferedReader(
						new InputStreamReader(s.getInputStream()));
				
				System.out.println(br.readLine());
				System.out.println();
				br.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
